package com.ruoyi.system.outto.goods.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.model.domain.*;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.core.OutUrlConstant;
import com.ruoyi.system.outto.goods.NEWSBOAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/6/5 16:19
 */
@Slf4j
@Service
public class NEWSBAPIImpl implements NEWSBOAPI {

    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;

    @Autowired
    private RedisCache redisCache;
    @Resource
    private ArtRecMapper artRecMapper;

    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto,  SalePartner salePartner) {
        String PATH = "/api/goods/UserGoods/addPost";
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner);
        log.info("少伯添加接口请求参数={}", JSONObject.toJSONString(params));
        String response = null;
        try {
            String url = OutUrlConstant.SBO + PATH;
            response = HttpUtils.sendPost(OutUrlConstant.SBO + PATH, JSON.toJSONString(params), getHeader(salePartner));
        } catch (IOException e) {
            e.printStackTrace();
            throw new GlobalException("接口异常");
        }
        log.info("少伯添加接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);
        if (!"1".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            String data = resultJson.getString("data");
            JSONObject jsonObject = JSON.parseObject(data);
            String item = jsonObject.getString("item");
            JSONObject itemJson = JSON.parseObject(item);
            String id = itemJson.getString("id");
            ArtRec artRecreq = new ArtRec();
            artRecreq.setConfig(salePartner.getId());
            artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
            List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
            if(artRecs.size()>0) {
                artRecs.get(0).setOutid(id);
                artRecMapper.updateArtRec(artRecs.get(0));
            }else{
                artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
                artRecreq.setCreateId(goodsInfoAndAttrValueDto.getCreateId());
                artRecreq.setType(LCConstant.interAdd);
                artRecreq.setConfig(salePartner.getId());
                artRecreq.setSaleCode(salePartner.getSaleName());
                artRecreq.setOutid(id);
                artRecMapper.insertArtRec(artRecreq);
            }
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("msg"));

        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto,  SalePartner salePartner) {

        Map<String, Object> params = new HashMap<>();


        String PATH = "/api/goods/UserGoods/editPost";
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        params.put("id", artRecs.get(0).getOutid());
        params.put("price", goodsInfoAndAttrValueDto.getPrice());
        params.put("quantity", "1");
        Map<String, Object> result = new HashMap<>();

        log.info("少伯改价接口请求参数={}", JSONObject.toJSONString(params));
        String response = "";
        try {
            response = HttpUtils.sendPost(OutUrlConstant.SBO + PATH, JSONObject.toJSONString(params), getHeader(salePartner));
        } catch (IOException e) {
            e.printStackTrace();
            throw new GlobalException("接口异常");
        }
        log.info("少伯改价接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);
        if (!"1".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("msg"));
        return AjaxResult.success(result);
    }


    private Map<String, Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        GameAttribute gameAttribute = null;
        String hours = "";
        String skins = "";
        String nobLeve = "";
        String campId = "";
        if(Objects.equals("王者荣耀", goodsInfoAndAttrValueDto.getGameName())) {
            hours = goodsInfoAndAttrValueDto.getF7()==null||goodsInfoAndAttrValueDto.getF7().equals("")?"0":goodsInfoAndAttrValueDto.getF7();
            skins = goodsInfoAndAttrValueDto.getF8()==null||goodsInfoAndAttrValueDto.getF8().equals("")?"0":goodsInfoAndAttrValueDto.getF8();
            GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF2()));
            nobLeve = gameAttribute1.getFieldName();
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
            campId = goodsInfoAndAttrValueDto.getF17()==null||goodsInfoAndAttrValueDto.getF17().equals("")?"123456":goodsInfoAndAttrValueDto.getF17();
        }
        if(Objects.equals("和平精英", goodsInfoAndAttrValueDto.getGameName())) {
            hours = goodsInfoAndAttrValueDto.getF8()==null||goodsInfoAndAttrValueDto.getF8().equals("")?"0":goodsInfoAndAttrValueDto.getF8();
            skins = goodsInfoAndAttrValueDto.getF9()==null||goodsInfoAndAttrValueDto.getF9().equals("")?"0":goodsInfoAndAttrValueDto.getF9();
            GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
            nobLeve = gameAttribute1.getFieldName();
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
            campId = goodsInfoAndAttrValueDto.getF13()==null||goodsInfoAndAttrValueDto.getF13().equals("")?"123456":goodsInfoAndAttrValueDto.getF13();
        }
        if(goodsInfoAndAttrValueDto.getGameName().contains("原神")){
            hours = goodsInfoAndAttrValueDto.getF8()==null||goodsInfoAndAttrValueDto.getF8().equals("")?"0":goodsInfoAndAttrValueDto.getF8();
            skins = "0";
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
        }
        if(goodsInfoAndAttrValueDto.getGameName().contains("英雄联盟")){
            hours = goodsInfoAndAttrValueDto.getF3()==null||goodsInfoAndAttrValueDto.getF3().equals("")?"0":goodsInfoAndAttrValueDto.getF3();
            skins = goodsInfoAndAttrValueDto.getF4()==null||goodsInfoAndAttrValueDto.getF4().equals("")?"0":goodsInfoAndAttrValueDto.getF4();
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
        }
        if(goodsInfoAndAttrValueDto.getGameName().contains("穿越火线")){
            hours = goodsInfoAndAttrValueDto.getF11()==null||goodsInfoAndAttrValueDto.getF11().equals("")?"0":goodsInfoAndAttrValueDto.getF11();
            skins = String.valueOf(Integer.parseInt(goodsInfoAndAttrValueDto.getF8()==null||goodsInfoAndAttrValueDto.getF8().equals("")?"0":goodsInfoAndAttrValueDto.getF8())+
                    Integer.parseInt(goodsInfoAndAttrValueDto.getF9()==null||goodsInfoAndAttrValueDto.getF9().equals("")?"0":goodsInfoAndAttrValueDto.getF9())+
                    Integer.parseInt(goodsInfoAndAttrValueDto.getF10()==null||goodsInfoAndAttrValueDto.getF10().equals("")?"0":goodsInfoAndAttrValueDto.getF10()));
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
        }
        if(goodsInfoAndAttrValueDto.getGameName().contains("枪战王者")){
            skins = goodsInfoAndAttrValueDto.getF4()==null||goodsInfoAndAttrValueDto.getF4().equals("")?"0":goodsInfoAndAttrValueDto.getF4();
            hours = goodsInfoAndAttrValueDto.getF8()==null||goodsInfoAndAttrValueDto.getF4().equals("")?"0": String.valueOf(goodsInfoAndAttrValueDto.getF8().split(",").length);
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
        }
        Map<String, Object> params = new HashMap<>();

        params.put("delivery_type", "1");
        params.put("quantity", "0");
        Integer[] timeArr = {0, 24};
        params.put("trading_time", timeArr);
        params.put("bright_spot", gameAttribute.getFieldName() + "|皮肤数量 " + skins + "|英雄数量 " + hours);
        params.put("price", goodsInfoAndAttrValueDto.getPrice());
        params.put("title", "xyr" + goodsInfoAndAttrValueDto.getId() + "|" + goodsInfoAndAttrValueDto.getDes());
        params.put("description", "xyr" + goodsInfoAndAttrValueDto.getId() + "|" + goodsInfoAndAttrValueDto.getDes());


        GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
        goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
        goodsInfoImg.setType(Constants.STR_1);
        List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
        List<String> imgs = new ArrayList<>();

        if (!CollectionUtils.isEmpty(infoImgs)) {
            imgs = infoImgs.stream().map(im -> im.getImgUrl()).collect(Collectors.toList());
        } else {
            imgs.add(LCConstant.defaultImg);
        }
        String[] array1 = imgs.toArray(new String[imgs.size()]);
        params.put("image", array1);

        params.put("f1", "我是号主");
        params.put("f2", "无防沉迷");
        params.put("f4", nobLeve==null||nobLeve.equals("")?"无":nobLeve);

        if (gameAttribute.getFieldName().contains("可二次")) {
            params.put("f5", "是");
        } else {
            params.put("f5", "无");
        }

        if (Objects.equals("王者荣耀", goodsInfoAndAttrValueDto.getGameName())) {

            if (Objects.equals("安卓QQ", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "70582");
            }
            if (Objects.equals("安卓微信", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "71058");
            }
            if (Objects.equals("苹果QQ", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "71402");
            }
            if (Objects.equals("苹果微信", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "71536");
            }

            params.put("type", "317");

            params.put("f6", hours);
            params.put("f7", skins);
            params.put("f8", "");
            params.put("f9", "");
            params.put("f10", "");
            params.put("f11", "");
            params.put("f12", "");
            params.put("f13", "");
            params.put("f14", "");
            params.put("f15", "");
            params.put("f16", campId==null||campId.equals("")?"123456":campId);

        }
//        if (Objects.equals("永劫无间", accountInfo.getType())) {
//
//            params.put("bright_spot", "");
//            params.put("type", "387");
//
//            if (Objects.equals("Steam", accountInfo.getRegional())) {
//                params.put("game_id", "92477");
//            }
//            if (Objects.equals("网易", accountInfo.getRegional())) {
//                params.put("game_id", "92475");
//            }
//
//            params.put("f1", "手机账号");
//            params.put("f2", accountInfo.getHeroes());
//            params.put("f3", accountInfo.getSkins());
//            params.put("f4", "");
//            params.put("f5", "");
//            params.put("f6", "");
//            params.put("f7", "");
//            params.put("f8", "");
//            params.put("f9", "");
//            params.put("f10", "");
//            params.put("f11", "");
//            params.put("f12", "");
//            params.put("f13", "");
//            params.put("f14", "");
//            params.put("f15", "");
//            params.put("f16", "");
//            params.put("f17", "");
//            params.put("f18", "");
//            params.put("f19", "");
//            params.put("f20", "");
//        }
//        if (Objects.equals("QQ飞车手游", accountInfo.getType())) {
//
//            params.put("bright_spot", "");
//            params.put("type", "235");
//
//            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
//                params.put("game_id", "56763");
//            }
//            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
//                params.put("game_id", "56870");
//            }
//            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
//                params.put("game_id", "95475");
//            }
//            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
//                params.put("game_id", "95476");
//            }
//
//            params.put("f1", "");
//            params.put("f2", "");
//            params.put("f3", "");
//            params.put("f4", "");
//            params.put("f5", "");
//            params.put("f6", "");
//            params.put("f7", "");
//            params.put("f8", "");
//            params.put("f9", "");
//            params.put("f10", "");
//            params.put("f11", "");
//            params.put("f12", "");
//            params.put("f13", "");
//            params.put("f14", "");
//            params.put("f15", "");
//            params.put("f16", "");
//            params.put("f17", "");
//            params.put("f18", "");
//            params.put("f19", "");
//            params.put("f20", "");
//        }
//        if (Objects.equals("光遇", accountInfo.getType())) {
//
//            params.put("bright_spot", "");
//            params.put("type", "87");
//
//            if (Objects.equals("安卓网易邮箱", accountInfo.getRegional())) {
//                params.put("game_id", "22272");
//            }
//            if (Objects.equals("小米渠道服", accountInfo.getRegional())) {
//                params.put("game_id", "22293");
//            }
//            if (Objects.equals("VIVO渠道服", accountInfo.getRegional())) {
//                params.put("game_id", "22290");
//            }
//            if (Objects.equals("OPPO渠道服", accountInfo.getRegional())) {
//                params.put("game_id", "22287");
//            }
//            if (Objects.equals("华为渠道服", accountInfo.getRegional())) {
//                params.put("game_id", "22284");
//            }
//            if (Objects.equals("苹果网易邮箱", accountInfo.getRegional())) {
//                params.put("game_id", "22275");
//            }
//
//            params.put("f1", "手机账号");
//            params.put("f2", "");
//            params.put("f3", "");
//            params.put("f4", "");
//            params.put("f5", "");
//            params.put("f6", "原号主");
//            params.put("f7", "");
//            params.put("f8", "");
//            params.put("f9", "");
//            params.put("f10", "");
//            params.put("f11", "");
//            params.put("f12", "");
//            params.put("f13", "");
//            params.put("f14", "");
//            params.put("f15", "");
//            params.put("f16", "");
//            params.put("f17", "");
//            params.put("f18", "");
//            params.put("f19", "");
//            params.put("f20", "");
//        }
//        if (Objects.equals("火影忍者", accountInfo.getType())) {
//
//            params.put("bright_spot", "");
//            params.put("type", "100");
//
//            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
//                params.put("game_id", "25595");
//            }
//            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
//                params.put("game_id", "26717");
//            }
//            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
//                params.put("game_id", "25597");
//            }
//            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
//                params.put("game_id", "26719");
//            }
//
//            params.put("f1", "无防沉迷");
//            params.put("f2", "");
//            params.put("f3", "");
//            params.put("f4", "");
//            params.put("f5", "");
//            params.put("f6", "");
//            params.put("f7", "");
//            params.put("f8", "");
//            params.put("f9", "");
//            params.put("f10", "");
//            params.put("f11", "");
//            params.put("f12", "");
//            params.put("f13", "");
//            params.put("f14", "");
//            params.put("f15", "");
//            params.put("f16", "");
//            params.put("f17", "");
//            params.put("f18", "");
//            params.put("f19", "");
//            params.put("f20", "");
//        }
        if (Objects.equals("枪战王者", goodsInfoAndAttrValueDto.getGameName())) {

            params.put("bright_spot", "");
            params.put("type", "26");

            if (Objects.equals("安卓QQ", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "4870");
                params.put("f1", "安卓");
            }
            if (Objects.equals("安卓微信", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "4875");
                params.put("f1", "安卓");
            }
            if (Objects.equals("苹果QQ", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "4868");
                params.put("f1", "苹果");
            }
            if (Objects.equals("苹果微信", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "4873");
                params.put("f1", "苹果");
            }


            params.put("f2", "我是号主");
            params.put("f3", "无防沉迷");
            params.put("f5", "0");
            params.put("f6", "0");
            params.put("f7", "");
            params.put("f8", "");
            params.put("f9", "");
            params.put("f10", "");
            params.put("f11", "");
            params.put("f12", "");
            params.put("f13", "");
            params.put("f14", "");
            params.put("f15", "");
            params.put("f16", "");
            params.put("f17", "");
            params.put("f18", "");
            params.put("f19", "");
            params.put("f20", "");
        }
        if (Objects.equals("穿越火线", goodsInfoAndAttrValueDto.getGameName())) {

//            params.put("delivery_type", "g.delivery_type=1");

            params.put("bright_spot", "");
            params.put("type", "29");

            if (Objects.equals("北部大区", goodsInfoAndAttrValueDto.getGroupName())) {
                params.put("game_id", "95474");

            }
            if (Objects.equals("南部大区", goodsInfoAndAttrValueDto.getGroupName())) {
                params.put("game_id", "95473");
            }
            if (Objects.equals("西部大区", goodsInfoAndAttrValueDto.getGroupName())) {
                params.put("game_id", "95472");
            }
            if (Objects.equals("东部大区", goodsInfoAndAttrValueDto.getGroupName())) {
                params.put("game_id", "95471");
            }

            params.put("f1", "原号主");
            params.put("f2", "无");
            if (gameAttribute.getFieldName().contains("可二次")){
                params.put("f3", "是");
            }else {
                params.put("f3", "无");
            }

            params.put("f5", "");
            params.put("f6", "");
            params.put("f7", "");
            params.put("f8", "");
            params.put("f9", "");
            params.put("f10", "");
            params.put("f11", "");
            params.put("f12", "");
            params.put("f13", "");
            params.put("f14", "");
            params.put("f15", "");
            params.put("f16", "");
            params.put("f17", "");
            params.put("f18", "");
            params.put("f19", "");
            params.put("f20", "");
        }
        if (Objects.equals("原神", goodsInfoAndAttrValueDto.getGameName())) {

            params.put("bright_spot", "");
            params.put("type", "385");

            params.put("game_id", "92461");
            params.put("f1", "手机账号");

            if ("可修改邮箱".equals(gameAttribute.getFieldName())){
                params.put("f2", "带邮箱出售");
            }
            if ("未绑定邮箱".equals(gameAttribute.getFieldName())){
                params.put("f2", "不出售邮箱");
            }


            params.put("f3", "1");
            params.put("f4", "1");
            params.put("f5", "1");
            params.put("f6", "0");
            params.put("f7", "");
            params.put("f8", "");
            params.put("f9", "");
            params.put("f10", "是");
            params.put("f11", "否");
            params.put("f12", "是");
            params.put("f13", "");
            params.put("f14", "");
            params.put("f15", "");
            params.put("f16", "");
            params.put("f17", "");
            params.put("f18", "");
            params.put("f19", "");
            params.put("f20", "");
        }
//        if (Objects.equals("逆战", goodsInfoAndAttrValueDto.getGameName())) {
//
//            params.put("bright_spot", "");
//            params.put("type", "211");
//
//            if (Objects.equals("网通", accountInfo.getRegional())) {
//                params.put("game_id", "39281");
//            }
//            if (Objects.equals("电信", accountInfo.getRegional())) {
//                params.put("game_id", "39279");
//            }
//            params.put("f1", "QQ等级0级");
//
//            params.put("f2", "有QQ好友");
//
//            params.put("f3", "10");
//            params.put("f4", "");
//            params.put("f5", "");
//            params.put("f6", "0");
//            params.put("f7", "");
//            params.put("f8", "");
//            params.put("f9", "");
//            params.put("f10", "");
//            params.put("f11", "");
//            params.put("f12", "");
//            params.put("f13", "");
//            params.put("f14", "");
//            params.put("f15", "");
//            params.put("f16", "");
//            params.put("f17", "");
//            params.put("f18", "");
//            params.put("f19", "");
//            params.put("f20", "");
//        }
        if (Objects.equals("英雄联盟", goodsInfoAndAttrValueDto.getGameName())) {

            params.put("delivery_type", "g.delivery_type=0");

            params.put("type", "401");

            if (Objects.equals("峡谷之巅", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93382");
            }
            if (Objects.equals("男爵领域", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93381");
            }
            if (Objects.equals("试炼之地", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93379");
            }
            if (Objects.equals("巨龙之巢", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93377");
            }
            if (Objects.equals("扭曲丛林", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93376");
            }
            if (Objects.equals("恕瑞玛", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93375");
            }
            if (Objects.equals("无畏先锋", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93374");
            }
            if (Objects.equals("弗雷尔卓德", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93373");
            }
            if (Objects.equals("德玛西亚", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93372");
            }
            if (Objects.equals("比尔吉沃特", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93371");
            }
            if (Objects.equals("皮城警备", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93369");
            }
            if (Objects.equals("卡拉曼达", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93368");
            }
            if (Objects.equals("征服之海", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93367");
            }
            if (Objects.equals("守望之海", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93366");
            }
            if (Objects.equals("影流", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93365");
            }
            if (Objects.equals("教育网专区", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93364");
            }
            if (Objects.equals("水晶之痕", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93363");
            }
            if (Objects.equals("均衡教派", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93362");
            }
            if (Objects.equals("钢铁烈阳", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93361");
            }
            if (Objects.equals("暗影岛", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93360");
            }
            if (Objects.equals("黑色玫瑰", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93359");
            }
            if (Objects.equals("裁决之地", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93358");
            }
            if (Objects.equals("雷瑟守备", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93357");
            }
            if (Objects.equals("巨神峰", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93356");
            }
            if (Objects.equals("战争学院", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93355");
            }
            if (Objects.equals("皮尔特沃夫", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93354");
            }
            if (Objects.equals("班德尔城", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93353");
            }
            if (Objects.equals("诺克萨斯", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93352");
            }
            if (Objects.equals("祖安", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93351");
            }
            if (Objects.equals("艾欧尼亚", goodsInfoAndAttrValueDto.getServerName())) {
                params.put("game_id", "93350");
            }
            params.put("f1", "当前赛季无排位");

            params.put("f2", "当前赛季无排位");

            params.put("f3", "当前赛季无排位");
            params.put("f4", "1");
            params.put("f5", hours);
            params.put("f6", skins);
            params.put("f7", "原号主");
            params.put("f8", "无防沉迷");
            if ("有修改人脸机会".contains(gameAttribute.getFieldName())){
                params.put("f9", "是");
            }else {
                params.put("f9", "否");
            }

            params.put("f10", "");
            params.put("f11", "");
            params.put("f12", "");
            params.put("f13", "");
            params.put("f14", "");
            params.put("f15", "");
            params.put("f16", "");
            params.put("f17", "");
            params.put("f18", "");
            params.put("f19", "");
            params.put("f20", "");
        }
        if (Objects.equals("和平精英", goodsInfoAndAttrValueDto.getGameName())) {

            params.put("bright_spot", gameAttribute.getFieldName() + "|枪皮数量 " + skins + "|套装数量 " + hours);

            params.put("f3", "0");
            params.put("f4", "");
            params.put("f5", hours);
            params.put("f6", skins);
            params.put("f7", "详情看图");

            if (Objects.equals("安卓QQ", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "23403");
            }
            if (Objects.equals("安卓微信", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "23406");
            }
            if (Objects.equals("苹果QQ", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "23409");
            }
            if (Objects.equals("苹果微信", goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName())) {
                params.put("game_id", "23412");
            }

            params.put("type", "98");
            params.put("f7", skins);
            params.put("f8", "");
            params.put("f9", "");
            params.put("f10", "");
            params.put("f11", "");
            params.put("f12", "");
            params.put("f13", "");
            params.put("f14", "");
            params.put("f15", "");
            params.put("f16", "");
            params.put("f17", "");
            params.put("f18", "");
            params.put("f19", "");
            params.put("f20", "");


            params.put("account_fields", "{\n" +
                    "        \"0\": \"11\",\n" +
                    "        \"1\": \"11\",\n" +
                    "        \"2\": \"11\"\n" +
                    "    }");


            if ("可二次实名".contains(gameAttribute.getFieldName())) {
                params.put("f11", "是");
            } else {
                params.put("f11", "无");
            }
        }

        params.put("mobile", "17120401234");
        params.put("qq", "111");
        params.put("wechat", "111");

        return params;
    }
    private List<GameAttribute> getGameAttributs(String ids) {
        return gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(ids.split(","),
                Long.class));
    }
    private String reIds(String allIds, String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            if (StringUtils.isNotEmpty(allIds)) {
                allIds = allIds + "," + ids;
            } else {
                allIds = ids;
            }
        }
        return allIds;
    }

    private Map<String, String> getHeader(SalePartner salePartner) {


        /**
         * XX-Token  9518d5daf5c7353d0895d2febc2815e79f3a2add4422aef74a893434ed2ffa6d
         * XX-Device-Type  pc
         * XX-App  trading
         * XX-Subsite  0
         */

        Object tokenJiuai = redisCache.getCacheObject(salePartner.getTwoOther());
        Map<String, String> header = new HashMap<>();
        if (Objects.nonNull(tokenJiuai)){

            header.put("XX-Token", tokenJiuai.toString());
            header.put("XX-Device-Type", "pc");
            header.put("XX-App", "trading");
            header.put("XX-Subsite", "0");
            header.put("Content-Type", "application/json");
        }

        return header;
    }

    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {

//        https://api2.shaobodaishou.com/api/goods/UserGoods/setStatus0
//        id
//        :
//        6719

        String path = "/api/goods/UserGoods/setStatus0";

        Map<String, Object> params = new TreeMap<>();
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        params.put("id", artRecs.get(0).getOutid());
        Map<String, Object> result = new HashMap<>();
        log.info("少伯下架接口请求参数={}", JSONObject.toJSONString(params));
        String response = "";
        try {
            response = HttpUtils.sendPost(OutUrlConstant.SBO + path, JSONObject.toJSONString(params), getHeader(salePartner));
        } catch (IOException e) {
            throw new GlobalException("接口异常");
        }
        if (StringUtils.isEmpty(response)) {
            throw new GlobalException("请求接口失败");
        }
        log.info("少伯下架接口返回参数={}", JSONObject.toJSONString(response));
        JSONObject resultJson = JSONObject.parseObject(response);
        if (!"1".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            ArtRec artRecreq1 = new ArtRec();
            artRecreq.setConfig(salePartner.getId());
            artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
            List<ArtRec> artRecs1 = artRecMapper.selectArtRecList(artRecreq1);
            artRecMapper.deleteArtRecById(artRecs1.get(0).getId());
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("msg"));
        return AjaxResult.success(result);
    }


    public static void main(String[] args) {

        /**
         * XX-Token  9518d5daf5c7353d0895d2febc2815e79f3a2add4422aef74a893434ed2ffa6d
         * XX-Device-Type  pc
         * XX-App  trading
         * XX-Subsite  0
         */

//        String username = "18924248888";
        String username = "15225247351";
        String password = "123456";
        String device_type = "pc";

        String url = "https://api2.shaobodaishou.com/api/user/public/login";

        Map<String, Object> params = new HashMap<>();
        params.put("username", username);
        params.put("password", password);
        params.put("device_type", device_type);

        String response = HttpUtils.sendPost(url, JSONObject.toJSONString(params), "application/json");
        System.out.println(response);


    }

}
